<template>
  <div>
    <Navbar appTitle="申请合格品入库" />
    <div class="search-content wrap-apply" :style="{top: GLOBAL.currentEnvironment ? '0' : '',height: GLOBAL.currentEnvironment ? '100vh' : 'calc(100vh - 1.12rem)',paddingBottom: GLOBAL.currentEnvironment ? '0.66rem' : ''}">
      <div v-for="(g, i) in tableData" :key="i">
        <van-cell-group style="margin-top: 0.1rem">
          <p class="label otherText">入库物料({{ i + 1 }})</p>
          <div class="bottomLine"></div>
          <p class="label FormTit"><span></span>工单编号</p>
          <div class="texts">{{ g.orderCode || '--'}}</div>
          <div class="bottomLine"></div>
        </van-cell-group>
        <van-cell-group>
          <p class="label FormTit"><span></span>批次编号</p>
          <div class="texts"><batch-production :code="g.batchCode" :id="g.batchId"></batch-production></div>
          <div class="bottomLine"></div>
        </van-cell-group>
        <van-cell-group>
          <p class="label FormTit"><span></span>生产物料</p>
          <div class="texts">{{ g.goodsName || '--'}}</div>
          <div class="bottomLine"></div>
        </van-cell-group>
        <van-cell-group>
          <p class="label FormTit"><span></span>规格</p>
          <div class="texts">{{ g.spec || '--'}}</div>
          <div class="bottomLine"></div>
        </van-cell-group>
        <van-cell-group>
          <p class="label FormTit"><span></span>数量</p>
          <div class="texts">{{ commafy(g.num) }}{{ g.basicUnitText}}</div>
          <div class="bottomLine"></div>
        </van-cell-group>
        <van-cell-group>
          <p class="label FormTit"><span></span>操作人</p>
          <div class="texts">{{ g.operatorName || '--'}}</div>
          <div class="bottomLine"></div>
        </van-cell-group>
        <van-cell-group>
          <p class="label FormTit"><span></span>提交人</p>
          <div class="texts">{{ g.applicantName || '--'}}</div>
          <div class="bottomLine"></div>
        </van-cell-group>
        <van-cell-group>
          <p class="label FormTit"><span></span>提交时间</p>
          <div class="texts">{{ g.applyTime || '--'}}</div>
        </van-cell-group>
        <div class="search-bottoms">
        <!-- <span class="btnconfirm" @click="btnConfirm">确定</span> -->
        <van-button type="info" :loading="loadingSubmit" class="btnconfirm" loading-text="提交中..." @click="submitProcess">提交</van-button>
      </div>
      </div>
      <Examine
        type="0"
        ref="Examine"
        @submitProcess="submitProcess"
        id="MESS_QUALIFIED_INBOUND_APPLY"
        :key="1"
        style="margin-top:0.1rem"
      />
    </div>
      
  </div>
</template>
<script>
import Navbar from "@/components/navBar/navBar_right";
import { qualifiedListApplyInBound, qualifiedList } from '@/api/system'
import { commafy } from '@/utils/util'
import Examine from "@/components/examine";
import BatchProduction from '@/components/BatchProduction'
export default {
  name: "materialRequisitionForm", //领料单
  components: {
    Navbar,
    Examine,
    BatchProduction
  },

  data() {
    return {
      commafy,
      repairForm: {},
      loadingSubmit: false,
      tableData: []
    };
  },
  beforeRouteLeave(to, from, next) {
    let that = this;
    switch (true) {
      case that.$refs.Examine.selectShow:
        that.$refs.Examine.selectShow = false;
        next(false);
        break;
      case !that.$refs.Examine.selectShow:
        next();
        break;
    }
  },
  computed: {},
  mounted() {},
  created() {
    this.getDetail();
  },
  methods: {
    getDetail() {
      let ids = this.$route.query.ids
      qualifiedList({ ids }).then((res) => {
        if (res.code == 200) {
          this.tableData = res.result.records
        }
      })
    },
    // 获取流程数据
    submitProcess(e) {
      if (e.nodeDtos && e.nodeDtos) {
        console.log(e);
        this.btnConfirm(e)
      } else {
        this.$refs.Examine.confirm();
      }
    },
    // 表单提交
    btnConfirm(e) {
      let parameter = {
        processDataVo: e,
        list: this.tableData
      }
      this.loadingSubmit = true
      qualifiedListApplyInBound(parameter).then(res => {
        if (res.code == 200) {
          this.$toast('申请入库成功！')
          this.$router.go(-1)
        } else {
          this.$toast(res.message)
        }
        this.loadingSubmit = false
      })
    },
  },
};
</script>
<style lang="scss" scoped>
.texts {
  padding: 0.1rem 0.16rem;color:#c8c9cc
}
/deep/.van-nav-bar {
  z-index: 99
}
@import "@/assets/theme.scss";
@import "@/views/workManagement/materialRequisition/materialForm.scss";
.search-bottoms {
  width: 100%;
  height: 0.5rem;
  background: #ffffff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: fixed;
  bottom: 0px;
  padding: 0rem 0.11rem;
  box-sizing: border-box;
  font-size: 0.16rem;
  font-weight: 500;
  z-index: 9;
  .btnconfirm {
    flex: 1;
    background: #1890ff;
    box-sizing: border-box;
    height: 0.39rem;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 0.03rem;
    color: #ffffff;
  }
}
</style>
